package com.efast.cafe.portal.controller.query;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.vo.DataTableVo;
import com.efast.cafe.portal.bean.query.FieldTypeBean;
import com.efast.cafe.portal.bean.query.FieldTypeOpBean;
import com.efast.cafe.portal.entity.query.FieldOp;
import com.efast.cafe.portal.entity.query.FieldType;
import com.efast.cafe.portal.service.query.IFieldTypeService;

@Controller
@RequestMapping("/frame_center/field")
public class FieldTypeContoller  extends AbstractController  {
	@Autowired
	private IFieldTypeService fieldTypeService;
	
	/**
	 * 字段类型列表
	 * @param request
	 * @param response
	 * @param fieldTypeBean
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/type/list")	
	public @ResponseBody DataTableVo<FieldTypeBean> typeList(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@ModelAttribute FieldTypeBean fieldTypeBean){
		
		return outPageJSONArray_bootstrapDatatable(fieldTypeService.selectFieldTypeById(fieldTypeBean));
	}
	/**
	 * 字段类型对应操作符列表
	 * @param request
	 * @param response
	 * @param fieldTypeOpBean
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/op/list")	
	public @ResponseBody DataTableVo<FieldTypeOpBean> opList(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@ModelAttribute FieldTypeOpBean fieldTypeOpBean){
		
		return outPageJSONArray_bootstrapDatatable(fieldTypeService.selectOpbyFieldTypeId(fieldTypeOpBean));
	}
	
	
	/**
	 * 字段类型增加
	 * @param request
	 * @param response
	 * @param fieldType
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/type/add")	
	public @ResponseBody String typeAdd(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@ModelAttribute FieldType fieldType){
		
		return super.tipJson(fieldTypeService.addFieldType(fieldType), ADD) ;
	}
	
	/**
	 * 字段类型对应操作符增加
	 * @param request
	 * @param response
	 * @param fieldOp
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/op/add")	
	public @ResponseBody String opAdd(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@ModelAttribute FieldOp fieldOp){
		
		return super.tipJson(fieldTypeService.addFieldOp(fieldOp), ADD) ;
	}
	
	/**
	 * 字段类型对应操作符删除
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/op/del")	
	public @ResponseBody String opDel(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@RequestParam Integer id){
		
		return super.tipJson(fieldTypeService.deleteFieldOp(id), DELETE) ;
	}
	
	/**
	 * 字段对应类型删除
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 * @throws JSONException
	 */
	@RequestMapping(value = "/type/del")	
	public @ResponseBody String typeDel(
			HttpServletRequest request, 
			HttpServletResponse response,		
			@RequestParam Integer id){
		
		return super.tipJson(fieldTypeService.deleteFieldType(id), DELETE) ;
	}
	
}
